#!/usr/bin/python
# -*- coding:utf-8 -*-
# @author  : micah
# @time    :  
# @function: 
# @version :


import asyncio


class Reader:
    """
    完成异步迭代器
    """

    def __init__(self):
        self.index = 0

    async def redline(self):
        self.index += 1
        if self.index == 100:
            return None
        await asyncio.sleep(1)
        return self.index

    def __aiter__(self):  # 普通函数
        return self

    async def __anext__(self):
        value = await self.redline()
        if value is None:
            raise StopAsyncIteration
        return value


async def main():
    async for i in Reader():
        print(i)


asyncio.run(main())

